package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.EDeviceBuyDao;
import com.hongxun.modules.eys.entity.EDeviceBuyEntity;
import com.hongxun.modules.eys.service.EDeviceBuyService;


@Service("eDeviceBuyService")
public class EDeviceBuyServiceImpl implements EDeviceBuyService {
    @Autowired
    private EDeviceBuyDao eDeviceBuyDao;

    @Override
    public EDeviceBuyEntity queryObject(String guid) {
        return eDeviceBuyDao.queryObject(guid);
    }

    @Override
    public List<EDeviceBuyEntity> queryList(Map<String, Object> map) {
        return eDeviceBuyDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return eDeviceBuyDao.queryTotal(map);
    }

    @Override
    public void save(EDeviceBuyEntity eDeviceBuy) {
        if (eDeviceBuy.getGuid() == null || eDeviceBuy.getGuid().equals("")) {

            eDeviceBuy.setGuid(UUID.randomUUID().toString());
        }
        eDeviceBuyDao.save(eDeviceBuy);
    }

    @Override
    public void update(EDeviceBuyEntity eDeviceBuy) {
        eDeviceBuyDao.update(eDeviceBuy);
    }

    @Override
    public void delete(String guid) {
        eDeviceBuyDao.delete(guid);
    }

    @Override
    public void deleteBatch(String[] guids) {
        eDeviceBuyDao.deleteBatch(guids);
    }

    @Override
    public void insertOrReplaceOrDelete(List<EDeviceBuyEntity> entities) {
        for (EDeviceBuyEntity d : entities) {
            if (d.getDBDatastate().equals("删除")) {
                eDeviceBuyDao.delete(d.getGuid());
            } else {
                EDeviceBuyEntity eCrossCostEntity = eDeviceBuyDao.queryObject(d.getGuid());
                if (eCrossCostEntity == null) {
                    eDeviceBuyDao.save(d);
                } else {
                    eDeviceBuyDao.update(d);
                }
            }
        }
    }

}
